package indigo.core;

import java.lang.reflect.Method;

import org.springframework.web.servlet.mvc.method.RequestMappingInfo;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;

public class DynamicRequestMappingHandlerMapping extends RequestMappingHandlerMapping {
	private Object handler;
	private String prefix;

	@Override
	protected void initHandlerMethods() {
		detectHandlerMethods(handler);
		handlerMethodsInitialized(getHandlerMethods());
	}

	@Override
	protected RequestMappingInfo getMappingForMethod(Method method, Class<?> handlerType) {
		RequestMappingInfo info = super.getMappingForMethod(method, handlerType);
		if (info != null) {
			RequestMappingInfo prefixInfo = RequestMappingInfo.paths(prefix).build();
			info = prefixInfo.combine(info);
		}
		return info;
	}

	public void setHandler(Object handler) {
		this.handler = handler;
	}

	public void setPrefix(String prefix) {
		this.prefix = prefix;
	}
}
